package com.service.impl;

import com.dao.LosearticleDao;
import com.entity.Losearticle;
import com.common.utils.Page;
import com.service.LosearticleService;
import com.service.LosearticleService;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * 用户Service接口实现类
 */
@Service("losearticleService")
@Transactional
public class LosearticleServiceImpl implements LosearticleService {
	// 注入LosearticleDao
	@Autowired
	private LosearticleDao losearticleDao;
	
	public Page<Losearticle> findLosearticleList(Integer page, Integer rows,String goods) {

			// 创建对象
	         Losearticle losearticle = new Losearticle();
	 		if(StringUtils.isNotBlank(goods)){
				losearticle.setGoods(goods);
			}
			// 当前页
			losearticle.setStart((page-1) * rows) ;
			// 每页数
			losearticle.setRows(rows);
			// 查询列表
			List<Losearticle> losearticles = 
	                            losearticleDao.selectLosearticleList(losearticle);
			// 查询列表总记录数
			Integer count = losearticleDao.selectLosearticleListCount(losearticle);
			Page<Losearticle> result = new Page<>();
			result.setPage(page);
			result.setRows(losearticles);
			result.setSize(rows);
			result.setTotal(count);
			return result;
	}

	@Override
	public int deleteLosearticle(Integer id) {
		// TODO Auto-generated method stub
		return losearticleDao.deleteLosearticle(id);
	}

	@Override
	public int createLosearticle(Losearticle losearticle) {
		// TODO Auto-generated method stub
		return losearticleDao.createLosearticle(losearticle);
	}

	@Override
	public Losearticle getLosearticleById(Integer id) {
		// TODO Auto-generated method stub
		return losearticleDao.getLosearticleById(id);
	}

	@Override
	public int updateLosearticle(Losearticle losearticle) {
		// TODO Auto-generated method stub
		return losearticleDao.updateLosearticle(losearticle);
	}

	@Override
	public int updateState(Losearticle losearticle) {
		// TODO Auto-generated method stub
		return losearticleDao.updateState(losearticle);
	}

	@Override
	public Page<Losearticle> findLosearticleListByUser(Integer page, Integer rows, String goods, String userid) {

		// 创建对象
         Losearticle losearticle = new Losearticle();
 		if(StringUtils.isNotBlank(goods)){
			losearticle.setGoods(goods);
		}
		// 当前页
		losearticle.setStart((page-1) * rows) ;
		// 每页数
		losearticle.setRows(rows);
		//查询所用的用户ID
		losearticle.setUserid(userid);
		// 查询列表
		List<Losearticle> losearticles = 
                            losearticleDao.selectLosearticleListByUser(losearticle);
		// 查询列表总记录数
		Integer count = losearticleDao.selectLosearticleListByUserCount(losearticle);
		Page<Losearticle> result = new Page<>();
		result.setPage(page);
		result.setRows(losearticles);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

	@Override
	public Page<Losearticle> findLosearticleListByState(Integer page, Integer rows, String goods) {

		// 创建对象
         Losearticle losearticle = new Losearticle();
 		if(StringUtils.isNotBlank(goods)){
			losearticle.setGoods(goods);
		}
		// 当前页
		losearticle.setStart((page-1) * rows) ;
		// 每页数
		losearticle.setRows(rows);
		// 查询列表
		List<Losearticle> losearticles = 
                            losearticleDao.selectLosearticleListByState(losearticle);
		// 查询列表总记录数
		Integer count = losearticleDao.selectLosearticleListByStateCount(losearticle);
		Page<Losearticle> result = new Page<>();
		result.setPage(page);
		result.setRows(losearticles);
		result.setSize(rows);
		result.setTotal(count);
		return result;
	}

}
